package com.whnk.web.controller.pm.project_manage;

import java.util.List;

import com.whnk.pm.domain.AttendanceInfo;
import com.whnk.pm.service.IAttendanceInfoService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;
import com.whnk.common.annotation.Log;
import com.whnk.common.enums.BusinessType;

import com.whnk.framework.web.base.BaseController;
import com.whnk.framework.web.page.TableDataInfo;
import com.whnk.common.base.AjaxResult;
import org.springframework.web.multipart.MultipartFile;

/**
 * 考勤导入 信息操作处理
 *
 * @author whwhnk
 * @date 2020-01-08
 */
@Controller
@RequestMapping("/pm/attendance")
public class AttendanceInfoController extends BaseController {

    @Autowired
    IAttendanceInfoService attendanceInfoService;

    private String prefix = "pm/attendance";

    @RequiresPermissions("pm:info:view")
    @GetMapping()
    public String info() {
        return prefix + "/attendanceInfo";
    }

    /**
     * 查询考勤导入列表
     */
    @RequiresPermissions("pm:info:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(AttendanceInfo info) {
        startPage();
        List<AttendanceInfo> list = attendanceInfoService.selectInfoList(info);
        return getDataTable(list);
    }

    /**
     * 新增考勤导入
     */
    @GetMapping("/add")
    public String add() {
        return prefix + "/add";
    }

    /**
     * 新增保存考勤导入
     */
    @RequiresPermissions("pm:info:add")
    @Log(title = "考勤导入", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(AttendanceInfo info) {
        return toAjax(attendanceInfoService.insertInfo(info));
    }

    /**
     * 修改考勤导入
     */
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Integer id, ModelMap mmap) {
        AttendanceInfo info = attendanceInfoService.selectInfoById(id);
        mmap.put("info", info);
        return prefix + "/edit";
    }

    /**
     * 修改保存考勤导入
     */
    @RequiresPermissions("pm:info:edit")
    @Log(title = "考勤导入", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(AttendanceInfo info) {
        return toAjax(attendanceInfoService.updateInfo(info));
    }

    /**
     * 删除考勤导入
     */
    @RequiresPermissions("pm:info:remove")
    @Log(title = "考勤导入", businessType = BusinessType.DELETE)
    @PostMapping("/remove")
    @ResponseBody
    public AjaxResult remove(String ids) {
        return toAjax(attendanceInfoService.deleteInfoByIds(ids));
    }


    @Log(title = "Excel导入考勤", businessType = BusinessType.UPDATE)
    @PostMapping("/upload")
    @ResponseBody
    public AjaxResult signExcelFileUpload(@RequestParam("signFileUpload") MultipartFile file) throws Exception {
        attendanceInfoService.signExcelFileUpload(file);
        return success();
    }
}
